<?php
namespace AuctionCore\Account\Back;

use AuctionCore\System\ListBase;
use AuctionCore\CarResource\CarModel;

//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: songaimin@clcw.com.cn  Blog:http://blog.csdn.net/samxx8        |
// +------------------------------------------------------------------------+
//


/**
 * "员工"列表
 * @author       爱民
 */
class EmployeeList extends ListBase
{

    private $base_sql = null;
    private $count_sql = null;

    public function __construct()
    {
        $query_sql = "SELECT e.*,d.name ";
        $sql = " FROM au_employee as e join au_depart as d on e.depart_id = d.id";
        $this->base_sql = $query_sql . $sql;
        $this->count_sql = "select count(*) count " . $sql;
    }


    /**
     * 获取列表结果
     * @param    int $ev_page_num 每页条数
     * @param    int $page 页码
     * @return   Object
     */
    public function get($ev_page_num, $page)
    {
        $dealer_id = $this->dealer_id;
        $Model = new \Think\Model();

        //拍单列表信息
        $sql = $this->base_sql;
        $sql .= " {$this->condition}";
        $skip = ($page < 2 ? 0 : $ev_page_num * ($page - 1));
        $sql .= " limit {$skip},{$ev_page_num}";
        $sql .= ";";
        // echo $sql;exit;
        $list = $Model->query($sql);
        return $list;
    }

    public function count()
    {
        $Model = new \Think\Model();
        $sql = $this->count_sql;
        $sql .= " {$this->condition}";
        $sql .= ";";
        $r = $Model->query($sql);
        return $r[0]['count'];
    }

    /**
     * 获取列表结果
     * @return   Object
     */
    public function getAll()
    {
        $dealer_id = $this->dealer_id;
        $Model = new \Think\Model();

        //拍单列表信息
        $sql = $this->base_sql;
        $sql .= " {$this->condition}";
        $sql .= ";";
        // echo $sql;exit;
        $list = $Model->query($sql);
        return $list;
    }

    /**
     * @param $ids
     * @return array
     */
    public function getEmpByIds($ids)
    {
        $data = M('employee')->field('emp_id,username')->where("emp_id IN($ids)")->select();
        $user = [];
        foreach ($data as $v) {
            $user[$v['emp_id']] = $v['username'];
        }
        return $user;

    }
}
